<?php

namespace App\Service\Index;

use App\Constants\ErrorCode;
use App\Helpers\ConfigUtil;
use App\Model\CallBase;
use App\Model\UserProfile;
use App\Service\CallBaseService;

/**
 * 获取声优的收费设置
 */
class GetCoinSettingService extends CallBaseService
{
    protected function RoVerifyList()
    {
        return [
            'host_id' => 'required|int',
        ];
    }

    public function handle()
    {
        $userId = $this->getUserId();
        $hostId = $this->request->input('host_id', 0);
        $callFrom = $this->request->input('call_from', 0);
        if (
            $callFrom == CallBase::FROM_DAILY_FREE || $callFrom == CallBase::FROM_QUICK_MESSAGE
        ) {
            return [
                'host_id' => $hostId,
                'coin_setting' => ConfigUtil::getQuickCallCoin('voice'),
                'video_coin_setting' => ConfigUtil::getQuickCallCoin('video')
            ];
        }
        $hostProfile = UserProfile::getProfile($hostId);
        if (!$hostProfile) {
            return $this->setError(ErrorCode::USER_NOT_VALID, '该用户信息异常，请稍后再尝试~');
        }
        //检测角色
        if (!UserProfile::checkIsHost($hostId, $hostProfile)) {
            $hostProfile = UserProfile::getProfile($userId);
            // return $this->setError(ErrorCode::USER_NOT_VALID, '该用户为普通用户，无法进行呼叫~');
        }
        return [
            'host_id' => $hostId,
            'coin_setting' => $hostProfile->coin_setting,
            'video_coin_setting' => $hostProfile->video_coin_setting,
        ];
    }
}
